import { mapState } from 'vuex';
import store from '@/store';
import notification from 'ant-design-vue/es/notification';
import router from '@/router/index'

const baseMixin = {
  computed: {
    ...mapState({
      layout: state => state.app.layout,
      navTheme: state => state.app.theme,
      primaryColor: state => state.app.color,
      colorWeak: state => state.app.weak,
      fixedHeader: state => state.app.fixedHeader,
      fixedSidebar: state => state.app.fixedSidebar,
      contentWidth: state => state.app.contentWidth,
      autoHideHeader: state => state.app.autoHideHeader,
      isMobile: state => state.app.isMobile,
      sideCollapsed: state => state.app.sideCollapsed,
      multiTab: state => state.app.multiTab
    }),
    isTopMenu () {
      return this.layout === 'topmenu'
    }
  },
  methods: {
    isSideMenu () {
      return !this.isTopMenu
    },
    err401 (err) {
      notification['error']({
        message: '登录失效',
        description: err.msg,
        duration: 4
      })
      store.dispatch('Logout').then(() => {
        router.push({path: '/login/login'})
      })
    }
  }
}

export {
  baseMixin
}
